<?php
namespace app\home\controller;

use app\common\logic\Diggings as DiggingsLogic;
use app\common\component\help_to\HelpToModel;
use app\common\component\help_get\HelpGetModel;
use app\common\component\help_get\HelpGetService;

class Diggings extends ControllerBase {
    public function index() {
    	return $this -> view -> fetch();
    }
	
	/*
	 * 抢单
	 */
	public function grabHlepGet() {
		$post = $this -> request -> post();
		if($this -> validate($post, ['help_get_id' => 'require|token']) !== true) {
			return json(['code' => -1, 'message' => '请勿重复提交!']);
		}

		return json((new DiggingsLogic()) -> grabHlepGet($post['help_get_id'], $post['action']));
	}

    public function diggingsOne() {
    	$userId = \think\Session::get('user_id');
    	$checkHelpTo = HelpToModel::get(['user_id' => $userId]);
    	if(!$checkHelpTo) {
    		$hasHelpGet = HelpGetModel::get(['user_id' => 1, 'status' => 9]);
    		if(!$hasHelpGet) {
    			$post['help_to_id'] = 0;
		    	$post['user_id'] = 1;
		    	$post['money'] = getParam('FIRST_ORDER_MONEY');
		    	$post['begin_time'] = $post['create_time'] = time();
		    	$post['status'] = 9;
	    		(new HelpGetService()) -> create($post);
    		}
    	}

    	$this -> view -> assign('helpGets', (new DiggingsLogic()) -> getHelpGets(0, 100, true));

    	return $this -> view -> fetch('diggings', [
    		'diggingsTitle' => '新手体验区',
    		'action' => 1
    	]);
    }

    public function diggingsTwo() {
    	$this -> view -> assign('helpGets', (new DiggingsLogic()) -> getHelpGets(10, 199));

    	return $this -> view -> fetch('diggings', [
    		'diggingsTitle' => '10~199接单区',
    		'action' => 2
    	]);
    }

    public function diggingsThree() {
    	$this -> view -> assign('helpGets', (new DiggingsLogic()) -> getHelpGets(200, 499));

    	return $this -> view -> fetch('diggings', [
    		'diggingsTitle' => '200~499接单区',
    		'action' => 3
    	]);
    }

    public function diggingsFour() {
    	$this -> view -> assign('helpGets', (new DiggingsLogic()) -> getHelpGets(500, 999));

    	return $this -> view -> fetch('diggings', [
    		'diggingsTitle' => '500~999接单区',
    		'action' => 4
    	]);
    }

    public function diggingsFive() {
    	$this -> view -> assign('helpGets', (new DiggingsLogic()) -> getHelpGets(1000, 999999));

    	return $this -> view -> fetch('diggings', [
    		'diggingsTitle' => '1000以上接单区',
    		'action' => 5
    	]);
    }
}